package com.cq.service.impl;

import com.cq.mapper.PermissionMapper;
import com.cq.pojo.Permission;
import com.cq.pojo.Role;
import com.cq.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 悠久的苍穹
 * @Date: 2021/2/7 18:12
 * @Description: ${description}
 * @Version: 1.0
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    PermissionMapper permissionMapper;

    @Override
    public List<Permission> findPermissionByRole(Role role) {
        return permissionMapper.findPermissionByRole(role);
    }

    @Override
    public List<Permission> getPermissions() {
        return permissionMapper.getPermissions();
    }

    @Override
    public List<Permission> getPermissionsById(Integer id) {
        return permissionMapper.getPermissionsById(id);
    }

    @Override
    public void updatePermission(String role_id, String id) {
        permissionMapper.deletePermission(role_id);
        String[] s = id.split(",");
        for (int i = 0; i < s.length; i++) {
            permissionMapper.addPermission(role_id,Integer.parseInt(s[i]));
        }
    }
}
